package com.sgb.kjwl.view.ui.activity.enterprise;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Point;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.databinding.DataBindingUtil;

import com.amap.api.maps.AMap;
import com.amap.api.maps.CameraUpdateFactory;
import com.amap.api.maps.MapView;
import com.amap.api.maps.model.BitmapDescriptorFactory;
import com.amap.api.maps.model.CameraPosition;
import com.amap.api.maps.model.LatLng;
import com.amap.api.maps.model.MyLocationStyle;
import com.sgb.alimaplibrary.MapMarkerTools;
import com.sgb.kjwl.AppActivity;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityAddNewQuoteBinding;
import com.sgb.kjwl.databinding.ActivityChooseQuoteLocationBinding;
import com.swgk.core.util.ClickUtils;

import static android.view.View.GONE;
import static android.view.View.VISIBLE;

/**
 * Time:2021/7/12
 * Author:黄淋
 * Description:选择地址页面
 */
public class AddNeedQuoteChooseLocationActivity extends AppActivity implements AMap.OnCameraChangeListener {
    private ActivityChooseQuoteLocationBinding mBinding;

    //地图控制器
    private AMap aMap;
    //地图缩放级别
    private final int zoomLevel = 17;

    public static void start(Context context) {
        Intent intent = new Intent();
        intent.setClass(context, AddNeedQuoteChooseLocationActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initMap(savedInstanceState);
    }

    @Override
    protected void initView() {
        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_choose_quote_location);
        initActionBar();
    }

    @Override
    protected void init() {

    }

    /**
     * 初始化导航栏，设置监听
     */
    private void initActionBar() {
        mBinding.ivBackRed.setOnClickListener(a -> finish());
        mBinding.editSearchRed.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (mBinding.editSearchRed.getText().toString().equals("")) {
                    mBinding.ivCloseRed.setVisibility(GONE);
                } else {
                    mBinding.ivCloseRed.setVisibility(VISIBLE);
                }
            }
        });

        mBinding.ivCloseRed.setOnClickListener(v -> {
            mBinding.editSearchRed.setText("");

        });

        mBinding.rightViewRed.setOnClickListener(a -> {
            closeKeybord();

        });
    }

    /**
     * 初始化地图
     */
    private void initMap(Bundle savedInstanceState) {
        mBinding.searchMapViewLocation.onCreate(savedInstanceState);
        //获取地图控制类
        aMap = mBinding.searchMapViewLocation.getMap();
        //设置缩放级别
        aMap.moveCamera(CameraUpdateFactory.zoomTo(zoomLevel));
        //显示定位蓝点
        aMap.getUiSettings().setMyLocationButtonEnabled(false);

//        //定位监听
//        aMap.setOnMyLocationChangeListener(this);
//        //地图点击监听
//        aMap.setOnMapClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.ll_to_choose_location://选择联系地址
                if (!ClickUtils.isDoubleClick()) {

                }
                break;

        }
    }

    @Override
    public void onCameraChange(CameraPosition cameraPosition) {
        LatLng target = cameraPosition.target;
    }

    @Override
    public void onCameraChangeFinish(CameraPosition cameraPosition) {

    }
}
